package com.fsquare.inventory.domain.catalog;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyTransform;
import org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyTransformMember;
import org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyTransformTypes;
import org.broadleafcommerce.common.presentation.AdminPresentation;
import org.broadleafcommerce.common.presentation.AdminPresentationClass;
import org.broadleafcommerce.common.presentation.AdminPresentationMap;
import org.broadleafcommerce.common.presentation.client.SupportedFieldType;
import org.broadleafcommerce.core.catalog.domain.ProductImpl;
import org.broadleafcommerce.core.catalog.domain.ProductOptionValue;
import org.broadleafcommerce.core.catalog.domain.SkuImpl;
import org.broadleafcommerce.core.catalog.domain.ProductImpl.Presentation;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fsquare.inventory.domain.SkuInventory;
import com.fsquare.inventory.domain.SkuMovement;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "FSQ_SKU")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "blProducts")
@AdminPresentationClass(friendlyName = "baseSku")
@DirectCopyTransform({
        @DirectCopyTransformMember(templateTokens = DirectCopyTransformTypes.SANDBOX, skipOverlaps=true),
        @DirectCopyTransformMember(templateTokens = DirectCopyTransformTypes.MULTITENANT_CATALOG)
})
public class FSQSkuImpl extends SkuImpl implements FSQSku {

	private static final long serialVersionUID = -1680332968141263664L;
	
//	protected SkuInventory skuInventory;
	
	@OneToMany(mappedBy = "sku", targetEntity = SkuMovement.class, cascade = {CascadeType.ALL})
	@OrderBy("updateDate")
    @BatchSize(size = 50)
    @AdminPresentationMap(friendlyName = "skuMovements", 
        tab = Presentation.Tab.Name.Inventory, tabOrder = Presentation.Tab.Order.Inventory,
        deleteEntityUponRemove = true, forceFreeFormKeys = true)
	protected List<SkuMovement> skuMovements = new ArrayList<SkuMovement>();

	public List<SkuMovement> getSkuMovements() {
		return skuMovements;
	}

	public void setSkuMovements(List<SkuMovement> skuMovements) {
		this.skuMovements = skuMovements;
	}

//	public SkuInventory getSkuInventory() {
//		return skuInventory;
//	}
//
//	public void setSkuInventory(SkuInventory skuInventory) {
//		this.skuInventory = skuInventory;
//	}
}
